# Just to demonstrate how one could design the widget api on the controller side
# This is assuming that we have a site object which has a nested sections tree. 

class ApplicationController < ActionController::Base

  acts_as_widgets_controller
  
  widget :sections,       :type => :tree_menu,
                          :object => lambda{|c| c.site.sections.root }, 
                          :url => :url_for
                    
  widget :admin_site,     :type => :tree_menu,
                          :object => lambda{|c| c.site.sections.root }, 
                          :partial => 'widgets/admin/site'
                    
  widget :admin_global,   :type => :menu,
                          :partial => 'widgets/admin/global'
                    
  widget :admin_section,  :type => :menu,
                          :partial => 'widgets/admin/section'
                          
  # just here to demostrate the delegation of url creation back to the controller
  # TODO put this into the section class
  def admin_section_path_for(section)
    case section.class.name
      when 'Blog'     then admin_articles_path section.site, section
      when 'Category' then admin_category_path section.site, section.blog, section
      else                  admin_section_path section.site, section
    end
  end
end
